#include <stdio.h>
#include <stdlib.h>
#include "aimage.h"
#include "aimage_utils.h"
#include "aimage_ppm.h"

int main( int argc, char *argv[] )
{
	AIMAGE image;
	float rg, gg, bg;

	if ( argc != 1 && argc != 2 )
	{
		fprintf(stderr, "%s [in_file]\n", argv[0] );
		exit( 1 );
	}

	if ( argc == 2 )
	{
		fprintf(stderr,"mincol reading from %s\n", 
			argv[1], rg, gg, bg );
		AIMAGE_PPM_UTILS::load( image, argv[1] );
	}
	else
	{
		fprintf(stderr,"mincol reading from stdin\n", 
			rg, gg, bg );
		AIMAGE_PPM_UTILS::load( image, "stdin" );
	}

	AIMAGE::const_iterator cur, end;

	cur= image.const_begin();
	end= image.const_end();

	APIXEL min;

	min.r = FULL_INT;
	min.g = FULL_INT;
	min.b = FULL_INT;

	while ( cur != end )
	{
		APIXEL p;
		p = *cur;

		if ( p.r < min.r )
		{
			min.r = p.r;
		}
		if ( p.g < min.g )
		{
			min.g = p.g;
		}
		if ( p.b < min.b )
		{
			min.b = p.b;
		}
		++cur;
	}

	printf("%g %g %g\n", 
		((float) min.r) / ((float) FULL_INT),
		((float) min.g) / ((float) FULL_INT),
		((float) min.b) / ((float) FULL_INT));
}

